<?php

namespace App\Http\Requests\Front;

use App\Http\Requests\Request;

class UserRegisterRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'user_name'=>'regex:/^[0-9a-zA-Z]*$/|required|unique:user,user_name|min:6|max:20',
            'phone'=>'required|regex:/^1[34578][0-9]{9}$/|unique:user,phone',
            'password'=>'required|min:6|max:20|confirmed',
            'password_confirmation'=>'required|',
            'chkCode'=>'required',
            'agreement'=>'required',
        ];
    }

    public function messages(){
        return [
            'user_name.regex'=>'用户名由字母和数字组成',
            'user_name.required'=>'请输入您的用户名',
            'user_name.unique'=>'该用户名已被使用',
            'user_name.min'=>'用户名至少6位',
            'user_name.max'=>'用户名至多20位',
            'phone.required'=>'请输入您的手机',
            'phone.regex'=>'请输入正确的手机格式',
            'phone.unique'=>'该手机号已被验证',
            'password.required'=>'请输入您的密码',
            'password.min'=>'密码至少为6位',
            'password.max'=>'密码不超过20位',
            'password_confirmation.required'=>'请确认密码',
            'password.confirmed'=>'密码确认不匹配',
            'chkCode.required'=>'请输入验证码',
            'agreement.required'=>'是否同意该章程',
        ];

    }
}
